package com.zy.composeworld.base

import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.zy.composeworld.base.adapter.BaseActivityAdapter
import com.zy.composeworld.base.bean.BaseMenuBean
import com.zy.composeworld.databinding.ActivityBaseMenuBinding
import java.util.ArrayList

abstract class BaseMenuActivity : BaseActivity<ActivityBaseMenuBinding>() {

    override fun ActivityBaseMenuBinding.initViewBinding() {
        //val recyclerView = findViewById<RecyclerView>(R.id.base_menu_rv)
        initAdapter()
    }

    open fun initAdapter() {
        val list: ArrayList<BaseMenuBean> = ArrayList()
        list.initList()
        val adapter = BaseActivityAdapter(list)
        binding.baseMenuRv.adapter = adapter
        binding.baseMenuRv.layoutManager = if (linear())
            LinearLayoutManager(baseContext, LinearLayoutManager.VERTICAL, false)
        else
            GridLayoutManager(baseContext, gridSize())
    }

    open fun linear() = true
    open fun gridSize() = 2

    override fun getViewBinding() = ActivityBaseMenuBinding.inflate(layoutInflater)

    open fun ArrayList<BaseMenuBean>.initList() {}


}